package hnlg.com.cn.controllers;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import hnlg.com.cn.common.RespBean;
import hnlg.com.cn.service.HetongService;
import hnlg.com.cn.vo.Hetong;
import lombok.extern.slf4j.Slf4j;

@Controller
@Slf4j
@RequestMapping("/HetongControl")
public class HetongController {
	List<Hetong> list=null;
	RespBean rb=null;
	Hetong vo=null;
	@Resource HetongService hetongService;
	
	@RequestMapping("/queryHetong")
	@ResponseBody
	public List<Hetong> queryhetong(
		@RequestParam(required=false,defaultValue="") String hetong_id,
		@RequestParam(required=false,defaultValue="") String house_id,
		@RequestParam(required=false,defaultValue="") String owner_phone){
		try{
			log.info("开始查询合同");
		   Hetong vo=new Hetong();
		   vo.setHetong_id(hetong_id);;
		   if(house_id!=null&!house_id.equals("")){
		   vo.setHouse_id(Integer.parseInt(house_id));}
		   vo.setOwner_phone(owner_phone);;
		   list=hetongService.queryHetong(vo);
		}catch(Exception e){
			e.printStackTrace();
		}
		return list;
	}
	//http://localhost:8044/test/hetongControl/addhetong?jzmc=基站2&hetong=C合同&mianji=888&dizhi=浙江绍兴&yzmc=林总&yzdh=777
	@RequestMapping("/addHetong")
	@ResponseBody
	public RespBean addhetong(Hetong vo){
		try {
			log.info("开始添加合同");
			hetongService.addHetong(vo);
			rb=new RespBean("msg","添加成功");
		} catch (Exception e) {
			e.printStackTrace();
			rb=new RespBean("msg","添加成功");
		}
		return rb;
	}
	//http://localhost:8044/test/hetongControl/deletehetong?id=12
	@RequestMapping("/deleteHetong")
	@ResponseBody
	public RespBean deletehetong(@RequestParam("id") String id){
		try{
			log.info("开始删除id="+id+"的合同");
			hetongService.deleteHetong(id);
			rb=new RespBean("msg","删除成功");
		}catch(Exception e){
			e.printStackTrace();
			rb=new RespBean("msg","删除失败");
		}
		return rb;
	}
	//http://localhost:8044/test/hetongControl/updatehetong?id=8&jzmc=基站2&hetong=C合同&mianji=888&dizhi=浙江绍兴&yzmc=林总&yzdh=777
	@RequestMapping("/updateHetong")
	@ResponseBody
	public RespBean updatehetong(Hetong vo){
		try{
			log.info("开始更新id="+vo.getId()+"的合同");
			boolean flag=hetongService.updateHetong(vo);
			System.out.println("=="+flag);
			rb=new RespBean("msg","更新成功");
		}catch(Exception e){
			e.printStackTrace();
			rb=new RespBean("msg","更新失败");
		}
		return rb;
	}
	//http://localhost:8044/test/hetongControl/queryvo?id=3
	@RequestMapping("/queryvo")
	@ResponseBody
	public Hetong queryvo(String id){
		try{
			log.info("开始查询id="+id+"的合同");
			vo=hetongService.queryById(id);
		}catch(Exception e){
			e.printStackTrace();
		}
		return vo;
	}

}
